class_name OperationManager extends Node

# 操作管理器，所有与游戏操作相关的内容放在这里
var is_can_control_camera = false	#是否可以控制摄像机
var is_can_click_point = true		#否可以点击point
var is_operationListening = false	#当前是否正在行动监听
var is_operation_end = true			#动作执行完毕，取消缩放隐藏动画不执行,默认执行完成

var selectedPoint:Point				#当前选中的point
var operationType = ""				#行动类型
var arr_listeningPoints = Array()	#正在监听行动的point列表

var smallOperation = SmallOperation.new().init(self)
var bigOperation = BigOperation.new().init(self)
var operation_幽灵 = 幽灵Operation.new().init(self)
var operation_恶灵 = 恶灵Operation.new().init(self)
var operation_炮台 = 炮台Operation.new().init(self)
var operation_狙炮 = 狙炮Operation.new().init(self)
var operation_地灵 = 地灵Operation.new().init(self)
var operation_精灵 = 精灵Operation.new().init(self)
var operation_沙兵 = 沙兵Operation.new().init(self)
var operation_沙皇 = 沙皇Operation.new().init(self)
var operation_野猪 = 野猪Operation.new().init(self)
var operation_野马 = 野马Operation.new().init(self)
var operation_拳师 = 拳师Operation.new().init(self)
var operation_灵阵 = 灵阵Operation.new().init(self)
var operation_天谕 = 天谕Operation.new().init(self)
var operation_妖术 = 妖术Operation.new().init(self)
var operation_鼓舞 = 鼓舞Operation.new().init(self)

func selectSmall(small:Small):
	small.click()
	is_can_click_point = false
	is_can_control_camera = false
	if small.player.is_me:
		ObjectManager.gameManager.ui.clickSmall()
	else :
		ObjectManager.gameManager.ui.clickOthers()


func selectBig(big:Big):
	big.click()
	is_can_click_point = false
	is_can_control_camera = false
	if big.player.is_me:
		match big.evolution:
			"未转型":
				ObjectManager.gameManager.ui.clickBig()
			"幽灵":
				ObjectManager.gameManager.ui.click幽灵()
			"恶灵":
				ObjectManager.gameManager.ui.click恶灵()
			"顽石":
				ObjectManager.gameManager.ui.click顽石()
			"炮台":
				ObjectManager.gameManager.ui.click炮台()
			"狙炮":
				ObjectManager.gameManager.ui.click狙炮()
			"地灵":
				ObjectManager.gameManager.ui.click地灵()
			"精灵":
				ObjectManager.gameManager.ui.click精灵()
			"黑伞":
				ObjectManager.gameManager.ui.click黑伞()
			"沙兵":
				ObjectManager.gameManager.ui.click沙兵()
			"沙皇":
				ObjectManager.gameManager.ui.click沙皇()
			"野猪":
				ObjectManager.gameManager.ui.click野猪()
			"野马":
				ObjectManager.gameManager.ui.click野马()
			"拳师":
				ObjectManager.gameManager.ui.click拳师()
			"灵阵":
				ObjectManager.gameManager.ui.click灵阵()
			"天谕":
				ObjectManager.gameManager.ui.click天谕()
			"妖术":
				ObjectManager.gameManager.ui.click妖术()
			"鼓舞":
				ObjectManager.gameManager.ui.click鼓舞()
	else :
		ObjectManager.gameManager.ui.clickOthers()


func selectPoint(point:Point):
	# 行动监听
	if is_operationListening:
		if point.is_waitingClick:
			match operationType:
				OperationType.small_born_big:
					smallOperation.smallBornBig(point)
				OperationType.big_born_big:
					bigOperation.bigBornBig(point)
				OperationType.big_move:
					bigOperation.bigMove(point)
				OperationType.big_attack:
					bigOperation.bigAttack(point)
				OperationType.幽灵_move:
					operation_幽灵.幽灵_move(point)
				OperationType.恶灵_attack:
					operation_恶灵.恶灵_attack(point)
				OperationType.恶灵_possess:
					operation_恶灵.恶灵_possess(point)
				OperationType.炮台_impact:
					operation_炮台.炮台_impact(point)
				OperationType.狙炮_aim:
					operation_狙炮.狙炮_aim(point)
				OperationType.地灵_move:
					operation_地灵.地灵_move(point)
				OperationType.地灵_抹平:
					operation_地灵.地灵_抹平(point)
				OperationType.地灵_占据:
					operation_地灵.地灵_占据(point)
				OperationType.精灵_move:
					operation_精灵.精灵_move(point)
				OperationType.精灵_赐福:
					operation_精灵.精灵_赐福(point)
				OperationType.精灵_庇护:
					operation_精灵.精灵_庇护(point)
				OperationType.沙兵_move:
					operation_沙兵.沙兵_move(point)
				OperationType.沙兵_attack:
					operation_沙兵.沙兵_attack(point)
				OperationType.沙皇_move:
					operation_沙皇.沙皇_move(point)
				OperationType.沙皇_attack:
					operation_沙皇.沙皇_attack(point)
				OperationType.野猪_impact:
					operation_野猪.野猪_impact(point)
				OperationType.野马_impact:
					operation_野马.野马_impact(point)
				OperationType.拳师_怒威神拳:
					operation_拳师.拳师_怒威神拳(point)
				OperationType.拳师_移动:
					operation_拳师.拳师_移动(point)
				OperationType.拳师_爆裂火拳:
					operation_拳师.拳师_爆裂火拳(point)
				OperationType.灵阵_迷雾森林:
					operation_灵阵.灵阵_迷雾森林(point)
				OperationType.灵阵_佛法慈悲:
					operation_灵阵.灵阵_佛法慈悲(point)
				OperationType.灵阵_九曲黄河:
					operation_灵阵.灵阵_九曲黄河(point)
				OperationType.灵阵_地狱杀伐:
					operation_灵阵.灵阵_地狱杀伐(point)
				OperationType.天谕_明魂搜根:
					operation_天谕.天谕_明魂搜根(point)
				OperationType.天谕_神兵天降:
					operation_天谕.天谕_神兵天降(point)
				OperationType.妖术_敲山震虎:
					operation_妖术.妖术_敲山震虎(point)
				OperationType.妖术_绝命献祭:
					operation_妖术.妖术_绝命献祭(point)
				OperationType.妖术_玄冰禁锢:
					operation_妖术.妖术_玄冰禁锢(point)
				OperationType.妖术_瘟疫传播:
					operation_妖术.妖术_瘟疫传播(point)
		is_operation_end = true
		ObjectManager.gameManager.ui.closeAll()
		return
	selectedPoint = point
	if point.small != null:
		ObjectManager.soundManager.play(SoundType.chess_select)
		selectSmall(point.small)
	elif point.big != null && point.big.visible:
		ObjectManager.soundManager.play(SoundType.chess_select)
		selectBig(point.big)
	ObjectManager.gameManager.camera.lensControl(point.position,Vector2(1.5,1.5))
	is_operation_end = false

func rightSelect(point:Point):
	if is_operationListening:
		return
	selectedPoint = point
	if point.small != null:
		selectSmall(point.small)
	elif point.big != null:
		selectBig(point.big)
	ObjectManager.gameManager.camera.quickControl(point.position)
	is_operation_end = false


func cancel():
	if is_operationListening:
		for p in arr_listeningPoints:
			p.default()
		arr_listeningPoints.clear()
	elif !is_operation_end:
		if selectedPoint.small != null:
			selectedPoint.small.detailHide()
		elif selectedPoint.big != null:
			selectedPoint.big.detailHide()
	is_can_click_point = true
	is_can_control_camera = true
	is_operationListening = false
	is_operation_end = true

func changeOperationType(ot:String):
	is_can_control_camera = true
	is_can_click_point = true
	is_operationListening = true
	self.operationType = ot
	match operationType:
		OperationType.small_born_big:
			smallOperation.preparation()
		OperationType.big_born_big:
			bigOperation.preparation_bornBig()
		OperationType.big_move:
			bigOperation.preparation_bigMove()
		OperationType.big_attack:
			bigOperation.preparation_bigAttack()
		OperationType.幽灵_move:
			operation_幽灵.preparation_幽灵_move()
		OperationType.恶灵_attack:
			operation_恶灵.preparation_恶灵_attack()
		OperationType.恶灵_possess:
			operation_恶灵.preparation_恶灵_possess()
		OperationType.炮台_impact:
			operation_炮台.preparation_炮台_impact()
		OperationType.狙炮_aim:
			operation_狙炮.preparation_狙炮_aim()
		OperationType.地灵_move:
			operation_地灵.preparation_地灵_move()
		OperationType.地灵_抹平:
			operation_地灵.preparation_地灵_抹平()
		OperationType.地灵_占据:
			operation_地灵.preparation_地灵_占据()
		OperationType.精灵_move:
			operation_精灵.preparation_精灵_move()
		OperationType.精灵_赐福:
			operation_精灵.preparation_精灵_赐福()
		OperationType.精灵_庇护:
			operation_精灵.preparation_精灵_庇护()
		OperationType.沙兵_move:
			operation_沙兵.preparation_沙兵_move()
		OperationType.沙兵_attack:
			operation_沙兵.preparation_沙兵_attack()
		OperationType.沙皇_move:
			operation_沙皇.preparation_沙皇_move()
		OperationType.沙皇_attack:
			operation_沙皇.preparation_沙皇_attack()
		OperationType.野猪_impact:
			operation_野猪.preparation_野猪_impact()
		OperationType.野马_impact:
			operation_野马.preparation_野马_impact()
		OperationType.拳师_怒威神拳:
			operation_拳师.preparation_拳师_怒威神拳()
		OperationType.拳师_移动:
			operation_拳师.preparation_拳师_移动()
		OperationType.拳师_爆裂火拳:
			operation_拳师.preparation_拳师_爆裂火拳()
		OperationType.灵阵_迷雾森林:
			operation_灵阵.preparation_灵阵_迷雾森林()
		OperationType.灵阵_佛法慈悲:
			operation_灵阵.preparation_灵阵_佛法慈悲()
		OperationType.灵阵_九曲黄河:
			operation_灵阵.preparation_灵阵_九曲黄河()
		OperationType.灵阵_地狱杀伐:
			operation_灵阵.preparation_灵阵_地狱杀伐()
		OperationType.天谕_明魂搜根:
			operation_天谕.preparation_天谕_明魂搜根()
		OperationType.天谕_天眼传真:
			operation_天谕.天谕_天眼传真(selectedPoint)
			return
		OperationType.天谕_神兵天降:
			operation_天谕.preparation_天谕_神兵天降()
		OperationType.妖术_敲山震虎:
			operation_妖术.preparation_妖术_敲山震虎()
		OperationType.妖术_玄冰禁锢:
			operation_妖术.preparation_妖术_玄冰禁锢()
		OperationType.妖术_瘟疫传播:
			operation_妖术.preparation_妖术_瘟疫传播()
		OperationType.妖术_绝命献祭:
			operation_妖术.preparation_妖术_绝命献祭()
		OperationType.鼓舞_嗜血狂战:
			operation_鼓舞.鼓舞_嗜血狂战(selectedPoint)
			return
		OperationType.鼓舞_乘风破浪:
			operation_鼓舞.鼓舞_乘风破浪(selectedPoint)
			return
		OperationType.鼓舞_生生不息:
			operation_鼓舞.鼓舞_生生不息(selectedPoint)
			return
		OperationType.鼓舞_常胜将军:
			operation_鼓舞.鼓舞_常胜将军(selectedPoint)
			return
		_:
			print("没有这种操作")
	# 如果没有可选落点直接取消
	if arr_listeningPoints.size() == 0:
		ObjectManager.toast.showToast("没有合适落点")
		ObjectManager.gameManager.ui.closeAll()
